$("#loginBtn").click((e) => {
    e.preventDefault();
    login();
})

const titleMap =  {
    'email': '邮箱',
    'password': '密码',
    'repassword': '重复密码',
    'code': '验证码',
}


function login() {
    let array = $("#loginForm").serializeArray();
    let obj = array.reduce((res, item) => {
        res[item['name']] = item['value'];
        return res;
    }, {});
//    console.log(obj);

   for (let key of Object.keys(obj)) {
        if (!obj[key]) {
            alert(`${titleMap[key]}不能为空`);
            return ;
        }
    }

    let url = `/api/user/login/${obj.email}/${obj.password}`;

  $.get(url, (data, status) => {
//       console.log(data);
        console.log(status);
       if (data.status != 0) {
           alert(data.message);
       } else {
           window.location.href = 'welcome.html';
       }
   });
}